<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // https://juejin.cn/post/7000739098730168350
        // https://juejin.cn/post/6844903605254750221
        function doubleMeanMethod(totalAmount, totalPeopleNum) {
           let amountList=[];
           let restAmount=totalAmount;//剩余金额
           let restPeopleNum=totalPeopleNum;//剩余红包数
           for(let i=0;i<totalPeopleNum-1;i++){
               let amount=randOne(1,restAmount/restPeopleNum *2);//[1,剩余人均金额两倍)
               restAmount-=amount;
               restPeopleNum--;
               amountList.push(amount);
           }
           amountList.push(restAmount);
           return amountList;
        }
      
        let money=100;//1元钱，就是100分
        let number=54;
        let amountList=doubleMeanMethod(money,number);
        let res=0;
        amountList.forEach((value,index)=>{
            console.log(`${index}:${value}`);
            amountList[index]/=100;
            res+=value;
        })
        console.log('res',res);
        console.log('amountList',amountList);

         // 获取闭区间 [n, m) 内的一个随机整数
         function randOne(n, m) {
            return Math.floor(Math.random() * (m - n)) + n;
        };
    </script>
</body>

</html>